import {createStore, applyMiddleware, combineReducers} from "redux";
import thunk from 'redux-thunk';
import {reducer as homeReducer} from '../pages/Home/store'
import {reducer as headerReducer} from '../components/Header/store'
import {reducer as translateReducer} from '../pages/Translate/store'
import createInstance from '../request';

const reducer = combineReducers({
  home: homeReducer,
  header: headerReducer,
  translate: translateReducer
});

export const getStore = (ctx/** ←koa的ctx*/) => {
  let defaultState = undefined;
  if (!__SERVER__) {
    console.log('window.context.state:', window.context.state);
    defaultState = window.context.state;
  }

  return createStore(reducer, defaultState, applyMiddleware(thunk.withExtraArgument(createInstance(ctx))))
};

export default getStore;
